package com.yxkj.syh.app.huarong.activities;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;
import androidx.lifecycle.MutableLiveData;

import com.syh.app.basic.base.BaseResponse;
import com.syh.app.basic.base.view_model.BaseViewModel;
import com.syh.app.basic.config.BasicConstants;
import com.syh.app.basic.utils.net.ApiObserver;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.yxkj.syh.app.huarong.bean.CreatOrderResponse;
import com.yxkj.syh.app.huarong.bean.OrderInfo;
import com.yxkj.syh.app.huarong.data_center.model.OrderModel;
import com.yxkj.syh.app.huarong.util.UserManager;

/**
 * 创建者：SYH
 * 时间：2020/5/20 17:34
 * 编辑者：SYH、
 * 标签：
 * 补充说明：
 */
public class MainVM extends BaseViewModel<ActivityEvent> {

    public MainVM(@NonNull Application application) {
        super(application);
    }

    public ObservableField<Boolean> ofQuickFache = new ObservableField<>(!UserManager.getUserManager().getUser().getEmpId().equals(BasicConstants.WAIDIAOSIJI_EMPID));

    public MutableLiveData<OrderInfo> mldScanCreatOrder = new MutableLiveData<>();

    /**
     * 根据采购单编号 生成会运单预览
     *
     * @param no
     */
    public void getOrderByPurchaseOrderNo(String no) {
        showLoading("getOrderByPurchaseOrderNo");
        OrderModel.getOrderModel().getOrderByPurchaseOrderNo(no, mLifecycleProvider.bindToLifecycle(), new ApiObserver<CreatOrderResponse>() {
            @Override
            public void onSuccess(CreatOrderResponse response) {
                hideLoading("getOrderByPurchaseOrderNo");
                mldScanCreatOrder.setValue(response.getData());
            }

            @Override
            public void onFailed(int code, String msg) {
                hideLoading("getOrderByPurchaseOrderNo");
            }
        });
    }

}
